import 'package:flutter/material.dart';
import 'package:get/get.dart';

void main() {
  runApp(const MyApp());
}


class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      initialRoute: RouteConfig.testOne,
      getPages: RouteConfig.getPages,
    );
  }
}

class RouteConfig {
  static const String testOne = "/testOne";
  static const String testTwo = "/testOne/testTwo";

  static final List<GetPage> getPages = [
    GetPage(
      name: testOne,
      page: () => TestOnePage(),
      binding: TestOneBinding(),
    ),
    GetPage(
      name: testTwo,
      page: () => TestTwoPage(),
      binding: TestTwoBinding(),
    ),
  ];
}



class TestOneLogic extends GetxController {
  void jump() => Get.toNamed(RouteConfig.testTwo);
}

///view层
class TestOnePage extends StatelessWidget {
  final logic = Get.find<TestOneLogic>();

   TestOnePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('页面一')),
      body: const Center(child: Text('页面一', style: TextStyle(fontSize: 30.0))),    
      floatingActionButton: FloatingActionButton(
        onPressed: () => logic.jump(),
        child: const Icon(Icons.arrow_forward),
      ),
    );

  }
}

///binding层
class TestOneBinding extends Bindings {
  @override
  void dependencies() {
    Get.lazyPut(() => TestOneLogic());
  }
}



class TestTwoLogic extends GetxController {

}

///view层
class TestTwoPage extends StatelessWidget {
  final logic = Get.find<TestTwoLogic>();

  TestTwoPage({super.key}); 

  @override

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('页面二')),
      body: const Center(child: Text('页面二', style: TextStyle(fontSize: 30.0))),
    );
  }

}

///binding层
class TestTwoBinding extends Bindings {
  @override
  void dependencies() {
    Get.lazyPut(() => TestTwoLogic());
  }
}



